﻿Imports DTO
Imports System.Data.SqlClient

Public Class StaffDAO
    Public Function GetListStaff() As List(Of StaffDTO)
        Dim listResult As New List(Of StaffDTO)
        Try
            'Dim sql As String = "select StaffID, isNull(Price,0) Price, isNull(Name,'') Name from Staff  order by Price "
            'Dim reader As SqlDataReader
            'reader = Connection.ExcuteReader(sql)
            'While (reader.Read)
            '    Dim Staff As New StaffDTO
            '    Staff.StaffID = reader("StaffID")
            '    Staff.Price = reader("Price")
            '    Staff.Name = reader("Name")
            '    listResult.Add(Staff)
            'End While
            'reader.Close()
            'Connection.Dispose()
        Catch ex As Exception
            Throw ex
        End Try
        Return listResult
    End Function

    Public Function GetStaffByIdPass(ByVal id As Integer, ByVal pass As String) As StaffDTO
        Dim result As New StaffDTO
        Try
            Dim sql As String = String.Format("SELECT top 1  ID, LName, FName, Role, pssword FROM Staff where pssword>'' and  id={0} and pssword='{1}' ", id, pass)
            Dim reader As SqlDataReader
            reader = Connection.ExcuteReader(sql)
            While (reader.Read)
                result.ID = reader("ID")
                result.LName = reader("LName")
                result.FName = reader("FName")
                result.Role = reader("Role")
                result.pssword = reader("pssword")
            End While
            reader.Close()
            Connection.Dispose()
        Catch ex As Exception
            Throw ex
        End Try
        Return result
    End Function

    Public Function GetStaffById(ByVal id As Integer) As StaffDTO
        Dim result As New StaffDTO
        Try
            Dim sql As String = String.Format("SELECT top 1  ID, LName, FName, Role, pssword FROM Staff where pssword>'' and  id={0}  ", id)
            Dim reader As SqlDataReader
            reader = Connection.ExcuteReader(sql)
            While (reader.Read)
                result.ID = reader("ID")
                result.LName = reader("LName")
                result.FName = reader("FName")
                result.Role = reader("Role")
                result.pssword = reader("pssword")
            End While
            reader.Close()
            Connection.Dispose()
        Catch ex As Exception
            Throw ex
        End Try
        Return result
    End Function

End Class
